<template>
  <div>
    <el-row class="row" :gutter="20">
      <el-col :span="21">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/teacher' }">教师菜单</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/teacher/choice' }">选题管理</el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
    </el-row>
    <el-table class="elTable" :data="choiceInfoList" border stripe height="630" v-loading="loading">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="choNo" label="选题编号" align="center"></el-table-column>
      <el-table-column class="row-stu-name" prop="stuName" label="学生姓名">
        <template slot-scope="scope">
          <el-button icon="iconfont icon-riqi" type="text" style="margin-left: 20px" @click="showStudentSign(scope.row.stuNo)" />
          <el-button type="text" @click="showStudentInfo(scope.row.stuNo)">{{ scope.row.stuName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="topNo" label="课题编号" align="center"></el-table-column>
      <el-table-column prop="topName" label="课题名称" :show-overflow-tooltip="true" align="center"></el-table-column>
      <el-table-column prop="choStateDesc" label="选题状态" align="center">
        <template slot-scope="scope">
          <span style="color: #ff6767">{{scope.row.choStateDesc}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="choAttach" label="选题附件" :show-overflow-tooltip="true" align="center"></el-table-column>
      <el-table-column prop="gmtCreate" label="选题时间" sortable align="center"></el-table-column>
      <el-table-column prop="gmtModify" label="更新时间" sortable align="center"></el-table-column>
      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button @click="detail(scope.row.stuNo)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <student-info :stuNo="stuNo" :visible.sync="profileVisible" />
    <teacher-sign-dialog :stuNo="stuNo" :visible.sync="signVisible" />
  </div>
</template>

<script>
import StudentInfo from '../student/StudentInfo'
import TeacherSignDialog from './TeacherSignDialog'

export default {
  name: 'TeacherChoice',
  components: {
    StudentInfo,
    TeacherSignDialog
  },
  data () {
    return {
      profileVisible: false,
      signVisible: false,
      loading: true,
      stuNo: '',
      choiceInfoList: []
    }
  },
  methods: {
    listChoiceInfo () {
      this.$axios.get('api/teacher/choice')
        .then(response => {
          let result = response.data
          if (result.success) {
            this.choiceInfoList = result.data
            console.log('choiceInfoList', this.choiceInfoList)
          } else {
            this.$message.error(result.msg)
          }
          this.loading = false
        })
    },
    showStudentInfo (stuNo) {
      this.stuNo = stuNo
      this.profileVisible = true
    },
    showStudentSign (stuNo) {
      this.stuNo = stuNo
      this.signVisible = true
    },
    detail (stuNo) {
      this.$router.push({ path: `/teacher/choice/${stuNo}` })
    }
  },
  mounted () {
    this.listChoiceInfo()
  }
}
</script>

<style lang="stylus" scoped>
.row {
  margin: 20px;
}

.elTable >>> .is-leaf {
  text-align: center;
}
</style>
